package com.kgar.repository;

import com.kgar.entity.graph.relationship.MatchWithRelation;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface MatchWithRepository extends Neo4jRepository<MatchWithRelation, Long> {
    @Transactional
    @Query("MATCH (r:Resume {resumeId: $resumeId}), (jp:JobPosition {jobPositionId: $jobPositionId}) "
            + "MERGE (r)-[rel:MATCH_WITH]->(jp) "
            + "ON CREATE SET rel.matchScore = $newMatchScore "
            + "ON MATCH SET rel.matchScore = rel.matchScore + $newMatchScore "
            + "RETURN rel.matchScore as matchScore")
    MatchWithRelation updateOrCreateMatchWithRelation(@Param("resumeId") Integer resumeId,
                                                      @Param("jobPositionId") Long jobPositionId,
                                                      @Param("newMatchScore") Double newMatchScore);
}
